package com.wsj.aop.customize;

import com.wsj.services.impl.ProxyTestImpl;
import java.lang.reflect.Method;
import org.springframework.aop.ClassFilter;
import org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor;

/**
 * description:静态普通方法名匹配切面
 *
 * @author yang
 * @date 2019/2/22 11:29
 */
public class CustomizeStaticPointcutAdvisor extends StaticMethodMatcherPointcutAdvisor {

  private final static String METHOD_NAME = "print";

  /**
   * 静态方法匹配判断，这里只有方法名为sayHello的，才能被匹配
   */
  @Override
  public boolean matches(Method method, Class<?> targetClass) {
    return METHOD_NAME.equals(method.getName());
  }

  /**
   * 覆盖getClassFilter，只匹配ProxyTestImpl类
   */
  @Override
  public ClassFilter getClassFilter() {
    return ProxyTestImpl.class::isAssignableFrom;
    /*return new ClassFilter() {
      @Override
      public boolean matches(Class<?> clazz) {
        return ProxyTestImpl.class.isAssignableFrom(clazz);
      }
    };*/
  }
}
